<?php

//CONNECT TO DB
 $con = mysql_connect("localhost","bob",""); 
 mysql_select_db("city",$con);

//FETCH CLASSIFICATIONS
 echo "var classifications=new Array();";
 echo "var classificationsWithNumbers=new Array();";
 $result = mysql_query("SELECT * FROM classifications");
 for($i=0;$row = mysql_fetch_array($result);$i++){
  $classification=$row['classification'];
  echo "classifications[".$i."]='".$classification."';";
  $result2=mysql_query("select id from published_articles where classification='".$classification."'");
  $j;for($j=0;$row2=mysql_fetch_array($result2);$j++);
  echo "classificationsWithNumbers[".$i."]='".$classification." (".$j.")';";
 }

//FETCH EMPRESAS (if requested)

 $sql_request="0";

 if(isset($_REQUEST['registerNumber'])){
  $sql_request="SELECT * FROM published_articles WHERE id='".$_REQUEST['registerNumber']."'";
 }

 if(isset($_REQUEST['searchSelect'])){
  $searchSelect=$_POST["searchSelect"];
  $searchSelect=strtok($searchSelect,"(");//kitamos los numeros de la clasificacion
  $sql_request="SELECT * FROM published_articles WHERE classification='".$searchSelect."'";
 }

 if($sql_request!="0"){
  echo "var empresas=new Array();";echo "var empresa;";
  $result=mysql_query($sql_request);
  for($i=0;$row = mysql_fetch_array($result);$i++){
   echo "empresa=new Empresa();";
    echo "empresa.name='".$row['name']."';";
    echo "empresa.lat='".$row['lat']."';";
    echo "empresa.lng='".$row['lng']."';";
    echo "empresa.classification='".$row['classification']."';";
    echo "empresa.street='".$row['street']."';";
    echo "empresa.number='".$row['number']."';";
    echo "empresa.postalcode='".$row['postalcode']."';";
    echo "empresa.tel='".$row['tel']."';";
    echo "empresa.page='".$row['page']."';";
    echo "empresa.mail='".$row['mail']."';";
   echo "empresas[".$i."]=empresa;";
  }//i
 }

?>
